package cn.lf.android.lawfirm.worklog.view;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.lf.android.lawfirm.R;
import cn.lf.android.lawfirm.changeapproval.ChangeApprovalActivity;
import cn.lf.android.lawfirm.distribution.modle.LawCase;
import cn.lf.android.lawfirm.worklog.WorkLogActivity;
import cn.lf.android.lawfirm.worklog.molde.WorkLog;

import static cn.lf.android.lawfirm.R.id.creat_people;
import static cn.lf.android.lawfirm.R.id.head_left;
import static cn.lf.android.lawfirm.R.id.proposer;

public class WorkLogAdapter extends BaseAdapter {
    private List<WorkLog> list;
    private LayoutInflater inflater;
    private Activity context;
    private int mPosition = 0;
    int width = 0;
    private int type;

    public WorkLogAdapter(Activity context, List<WorkLog> list, int type) {
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_work_log, null);
            holder.theme = (TextView) convertView
                    .findViewById(R.id.theme);
            holder.type = (TextView) convertView
                    .findViewById(R.id.type);
            holder.right_two = (TextView) convertView
                    .findViewById(R.id.right_two);
            holder.right_one = (TextView) convertView
                    .findViewById(R.id.right_one);
            holder.head_right = (TextView) convertView
                    .findViewById(R.id.head_right);
            holder.head_left = (TextView) convertView
                    .findViewById(head_left);
            holder.proposer = (TextView) convertView
                    .findViewById(proposer);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final WorkLog bean = list.get(position);
        holder.proposer.setText("申请人：" + bean.Proposer);
        holder.theme.setText("日志主题：" + bean.LogTheme);
        holder.type.setText("日志类型：" + bean.LogWorkType);
        holder.head_left.setText("日期：" + bean.createTime);
        holder.right_one.setText(bean.btnName);
        holder.head_right.setText(bean.LogStates);
        holder.right_two.setVisibility(View.GONE);
        holder.right_one.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, WorkLogActivity.class);
                intent.putExtra("status", bean.btnName);
                intent.putExtra("LsysLogID", bean.LsysLogID);
                context.startActivity(intent);
            }
        });
        return convertView;
    }

    class ViewHolder {
        TextView head_left, head_right, theme, type, right_two, right_one, proposer;
    }

}
